import * as echarts from 'echarts'
import { yAxis, xAxis, grid, nowSize } from '@/assets/js/echarts/config'

const rhftsrEcharts = ({
    tagId, data = {},
}) => {
    const myChart = echarts.init(document.getElementById(tagId));
    myChart.clear()
    const option = {
        grid,
        legend: {
            right: '2%',
            top: 0,
            itemHeight: 6,
        },
        tooltip: {
            trigger: 'axis',
        },
        xAxis: {
            type: 'category',
            data: data.x,
            ...xAxis,
            axisLabel: {
                show: true,
                color: '#999999',
                fontSize: 11,
                formatter: (val) => val.substr(-2),
            },

        },
        yAxis: {
            type: 'value',
            ...yAxis,

        },
        series: [{
            name: '本年',
            data: data.year,
            type: 'line',
            color: '#5655da',
            lineStyle: {
                normal: {
                    width: 1,
                },
            },
            areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#a9a9ec'
                }, {
                    offset: 0.9,
                    color: '#fff'
                }])
            }
        }, {
            name: '去年',
            data: data.lastYear,
            type: 'line',
            color: '#de8969',
            lineStyle: {
                normal: {
                    width: 1,
                },
            },
            areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#e6d0d1'
                }, {
                    offset: 0.9,
                    color: '#fff'
                }])
            }
        }]
    }
    myChart.setOption(option)
    // 图表自适应
    window.addEventListener('resize', function () {
        myChart.resize();
    })
}

const qdwdqlsrEcharts = ({
    tagId, data = {},
}) => {
    const myChart = echarts.init(document.getElementById(tagId));
    myChart.clear()
    const option = {
        grid,
        legend: {
            right: '2%',
            top: 0,
            itemHeight: 6,
        },
        tooltip: {
            trigger: 'axis',
        },
        xAxis: {
            type: 'category',
            data: data.x,
            ...xAxis,
            axisLabel: {
                show: true,
                color: '#999999',
                fontSize: 11,
                formatter: (val) => val.substr(-2),
            },

        },
        yAxis: {
            type: 'value',
            ...yAxis,

        },
        series: [{
            name: '本年',
            data: data.year,
            type: 'line',
            color: '#6b92dc',
            lineStyle: {
                normal: {
                    width: 1,
                },
            },
            areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#6b92dc'
                }, {
                    offset: 0.9,
                    color: '#fff'
                }])
            }
        }, {
            name: '去年',
            data: data.lastYear,
            type: 'line',
            color: '#a1e2b4',
            lineStyle: {
                normal: {
                    width: 1,
                },
            },
            areaStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: '#a1e2b4'
                }, {
                    offset: 0.9,
                    color: '#fff'
                }])
            }
        }]
    }
    myChart.setOption(option)
    // 图表自适应
    window.addEventListener('resize', function () {
        myChart.resize();
    })
}
export {
    rhftsrEcharts,
    qdwdqlsrEcharts
}